package com.gdut.simple.view.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.gdut.simple.R;

public class CommentPopupWindow extends PopupWindow {

    private EditText mInputText;

    public CommentPopupWindow(Context context, final DoneListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_publish_comment_window, new LinearLayout(context), false);
        mInputText = (EditText) view.findViewById(R.id.id_comment_content_text);
        final Button done = (Button) view.findViewById(R.id.id_publish_comment_button);
        done.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick(view, mInputText.getText().toString());
                }
            }
        });
        this.setContentView(view);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        ColorDrawable bd = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(bd);
        this.setAnimationStyle(R.style.bottom_popup_anim);
        this.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    }

    public String getInputText() {
        return mInputText.getText().toString();
    }

    public interface DoneListener {
        void onClick(View view, String result);
    }

}
